home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////
- // //
- // Tester.c for SerialTester //
- // //
- // © 1996 1 A.M. Productions and J. McCornack //
- // September 9,1996 //
- // //
- // This demonstrates serial encoding based //
- // on simple mathmatical functions performed //
- // on one seed number split in half. Both //
- // encoding processes are the same for the //
- // sake of demonstration. //
- // //
- // Tests for serial numbers created by //
- // SerialGenerator. //
- // //
- //////////////////////////////////////////////////
-
- #ifndef __MAIN__
- #include "Tester.h"
- #endif
-
- void main()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
-
- GetNumber(); // Ask the user for serial numbers to test
-
- FlushEvents(everyEvent,0);
- }
-
- void GetNumber()
- {
- short itemHit, itemType, i;
- Handle itemHandle;
- Rect itemRect;
- Str255 number;
- DialogPtr dialog;
- GrafPtr oldPort;
-
- GetPort(&oldPort);
- dialog=GetNewDialog(129,nil,(WindowPtr)-1); //129 is the Tester dialog
- ShowWindow(dialog);
- SelectWindow(dialog);
- SetPort(dialog);
- GetDialogItem(dialog,3,&itemType,&itemHandle,&itemRect);
- SetDialogItemText(itemHandle,"\p000-930-526-002"); //Start with a good one
-
- itemHit=-1;
-
- while (itemHit !=2)
- {
- ModalDialog(StdFilter, &itemHit);
-
- if (itemHit == 2)
- {
- SetPort(oldPort);
- DisposeDialog(dialog);
- ExitToShell();
- }
- if (itemHit == 1)
- {
- for (i=1;i <=15; i++)
- number[i] = '0';
- GetDialogItem(dialog,3,&itemType,&itemHandle,&itemRect);
- GetDialogItemText(itemHandle,number);
- if (CheckValue(number))
- {
- GetDialogItem(dialog,4,&itemType,&itemHandle,&itemRect);
- SetDialogItemText(itemHandle,"\p Good!");
- SysBeep(1);
- }
- else
- {
- GetDialogItem(dialog,4,&itemType,&itemHandle,&itemRect);
- SetDialogItemText(itemHandle,"\p No good.");
- }
-
- }
- }
- }
-
- pascal Boolean StdFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
- {
- char theChar;
- short itemKind;
- Handle itemHandle;
- Rect itemBox;
-
- switch ( theEvent->what )
- {
- case keyDown:
- theChar = (char)(theEvent->message & charCodeMask);
- if ( (((theEvent->modifiers & cmdKey) != 0) && (theChar == '.')) || (theChar == (char)27) ) /*cmd-. or ESC*/
- {
- *itemHit = kCancelButton;
- GetDItem(theDialog, kCancelButton, &itemKind, &itemHandle, &itemBox);
- HiliteControl((ControlHandle)itemHandle, 1);
- return true;
- }
- if ( (theChar == (char)13) || (theChar == (char)3) )
- {
- *itemHit = kOKButton;
- GetDItem(theDialog, 1, &itemKind, &itemHandle, &itemBox);
- HiliteControl((ControlHandle)itemHandle, kOKButton);
- return true;
- }
- break;
- case updateEvt:
- BeginUpdate(theDialog);
- SetPort(theDialog);
- DrawDialog(theDialog);
- GetDItem(theDialog, kOKButton, &itemKind, &itemHandle, &itemBox);
- InsetRect(&itemBox, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(&itemBox, 15, 15);
- EndUpdate(theDialog);
- break;
- }
- return false;
- }
-
- Boolean CheckValue(Str255 valStr)
- {
- long i,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12;
- long val1,val2,val3,val4;
- long temp1, temp2;
-
- i=1;
- // Parse through string and pull out digits.
- // This allows you to encode your serial numbers further
- // by adding letters and symbols - A154TG234453-H452
-
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d1 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d2 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d3 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d4 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d5 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d6 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d7 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d8 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d9 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d10 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d11 = valStr[i++] - '0';
- while ((valStr[i] < '0') || (valStr[i] > '9')) i++;
- d12 = valStr[i++] - '0';
-
- d1 = (d1*100);
- d2 = (d2*10);
-
- temp1 = d1+d2+d3;
-
- d2 = d2 + 10;
- d3 = d3 + 3;
- d2 = d2 + ((d3/10)*10);
- d1 = d1 + ((d2/100)*100);
- d1 = d1-((d1/1000)*1000);
- d2 = d2-((d2/100)*100);
- d3 = d3-((d3/10)*10); // Add 13
-
- val1 = (d3*100)+(d2)+(d1/100); // Stir Numbers
- val1 = val1 * 3; // Multiply by 3
- val1 = val1 - (temp1*2); // Subtract the original * 2
- if (val1<0)
- val1 = -val1; // Adjust if necessary
- d3 = (val1 % 10); // Reassign values
- d2 = ((val1 % 100)-d3)/10;
- d1 = ((val1 % 1000)-((d2*10)+d3))/100;
-
- val1 = (d1*100)+(d2*10)+d3;
- val2 = (d4*100)+(d5*10)+d6;
-
- // Second Number Set
-
- d10 = (d10*100);
- d11 = (d11*10);
-
- temp2 = d10+d11+d12;
-
- d11 = d11 + 10;
- d12 = d12 + 3;
- d11 = d11 + ((d12/10)*10);
- d10 = d10 + ((d11/100)*100);
- d10 = d10-((d10/1000)*1000);
- d11 = d11-((d11/100)*100);
- d12 = d12-((d12/10)*10); // Add 13
-
- val4 = (d12*100)+(d11)+(d10/100); // Stir Numbers
- val4 = val4 * 3; // Multiply by 3
- val4 = val4 - (temp2*2); // Subtract the original * 2
- if (val4<0)
- val4 = -val4; // Adjust if necessary
- d12 = (val4 % 10); // Reassign values
- d11 = ((val4 % 100)-d12)/10;
- d10 = ((val4 % 1000)-((d11*10)+d12))/100;
-
- val4 = (d10*100)+(d11*10)+d12;
- val3 = (d7*100)+(d8*10)+d9;
-
- if ((val1 == val2) && (val3 == val4))
- return (true);
- else
- return (false);
-
- }
-